<!--
 * @Author: your name
 * @Date: 2020-11-27 18:46:06
 * @LastEditTime: 2020-11-27 20:01:17
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wilde-survival-plant\src\views\system\information.vue
-->
<template>
  <div id="information">
    <el-form label-width="100px" size="mini">
      <el-form-item label="展示信息：">
        <el-input
          v-model="value"
          type="textarea"
          placeholder="请输入展示信息"
          :rows="10"
          resize="none"
          :disabled="isDisabled"
        />
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="onSubmit" v-permission="['管理者']">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {checkPermission} from '@/utils/index' // 权限判断函数
import { recommend, getrecommend } from '@/api/system'
export default {
  data() {
    return {
      value: ''
    }
  },
  computed: {
    isDisabled() {
      return !checkPermission(['管理者'])
    }
  },
  mounted() {
    this.getDetail()
    console.log(checkPermission(['管理者']))
  },
  methods: {
    async getDetail() {
      const res = await getrecommend(1)
      const code = Number(res.code)
      if (code === 200) {
        this.value = res.data.content
      }
    },
    async onSubmit() {
      const res = await recommend({ content: this.value })
      const code = Number(res.code)
      if (code === 200) {
        this.$message.success('保存成功')
        setTimeout(() => {
          window.location.reload()
        }, 500)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
#information{

}
</style>
